package main

import "fmt"

func main() {
	//第一种：定义变量，然后进行赋值
	var num1 int
	num1 = 30
	fmt.Printf("num1的数值是：%d\n", num1)

	//写在一行
	var num2 int = 15
	fmt.Printf("num2的数值是：%d\n", num2)

	//第二种：类型推断
	var user = "abc"
	fmt.Printf("类型是：%T，数值是:%s\n", user, user)

	//第三种：简短声明
	sum := 100
	fmt.Println(sum)

	//多个变量同时定义
	var a, b, c int
	a = 1
	b = 2
	c = 3
	fmt.Println(a, b, c)

	var m, n int = 100, 200
	fmt.Println(m, n)

	var n1, f1, s1 = 100, 3.14, "Go"
	fmt.Println(n1, f1, s1)

	//声明一组变量
	var (
		a3 int    = 128
		a4 int8   = 6
		a5 string = "hello"
		a6 rune   = 'A'
		a7 bool   = true
	)
	fmt.Println(a3, a4, a5, a6, a7) //128 6 hello 65 true

	var (
		name = "张三"
		age  = 21
		sex  = "男"
	)
	fmt.Printf("姓名：%s，年龄：%d，性别：%s\n", name, age, sex)

	//多变量声明也可以用在变量声明块中
	var (
		var1, var2, var3 int    = 5, 6, 7
		var4, var5, var6 rune   = 'C', 'D', 'E'
		var7, var8, var9 string = "C", "D", "E"
	)
	fmt.Println(var1, var2, var3, var4, var5, var6, var7, var8, var9) //5 6 7 67 68 69 C D E

	//交换两个数
	x := 1
	y := 2
	x, y = y, x
	fmt.Println(x, y) // 2 1
}
